package com.foreveross.taskservice.application.impl.task.mq;

import org.apache.activemq.broker.jmx.BrokerViewMBean;
import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.springframework.stereotype.Service;

import com.foreveross.taskservice.application.task.mq.IMQInfoApplication;
import com.foreveross.taskservice.common.CacheDataSpace;
import com.foreveross.taskservice.common.mq.QueueNameBuild;
import com.foreveross.taskservice.mq.mbean.MQViewMBeanProxyFactory;
@Service
public class MQInfoApplicationImpl  implements IMQInfoApplication{

	@Override
	public BrokerViewMBean getBrokerViewMBean() throws Exception {
		return MQViewMBeanProxyFactory.getInstance().getBorkerViewMBean();
	}

	@Override
	public QueueViewMBean getTaskQueueViewMBean(CacheDataSpace space,
			String channelId) throws Exception {
		return MQViewMBeanProxyFactory.getInstance().getQueueViewMBean(QueueNameBuild.buildTaskQueueName(space, channelId));
	}

	@Override
	public QueueViewMBean getRollQueueViewMBean(CacheDataSpace space) throws Exception {
		return MQViewMBeanProxyFactory.getInstance().getQueueViewMBean(QueueNameBuild.buildRollQueueName(space));
	}

	@Override
	public long getTaskQueueSize(CacheDataSpace space, String channelId)
			throws Exception {
		QueueViewMBean mBean=this.getTaskQueueViewMBean(space, channelId);
		return mBean==null?0:mBean.getQueueSize();
	}

	@Override
	public long getRollQueueSize(CacheDataSpace space) throws Exception {
		QueueViewMBean mBean=this.getRollQueueViewMBean(space);
		return mBean==null?0:mBean.getQueueSize();
	}
}
